#include <stdio.h>

int htoi(char s[]);

int main()
{
    printf("0x32Ab120F = %d\n", htoi("0x32Ab120F"));
    printf("0X32Ab120F = %d\n", htoi("0X32Ab120F"));
    printf("0Xff = %d\n", htoi("0xff"));
    return 0;
}

int htoi(char s[])
{
    int i, n = 0;
    if(s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
    {
        for(i = 2; ; i++)
        {
            if(s[i] >= '0' && s[i] <= '9') 
                n = n * 16 + (s[i] - '0');
            else if(s[i] >= 'a' && s[i] <= 'f') 
                n = n * 16 + (s[i] - 'a' + 10);
            else if(s[i] >= 'A' && s[i] <= 'F') 
                n = n * 16 + (s[i] - 'A' + 10);
            else
                break;
                        
        }
    }
    return n;
} 